package com.atguigu.day08;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Flink08_KafkaToKafka {
    public static void main(String[] args) {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //2.获取表的执行环境
        StreamTableEnvironment tableEnv= StreamTableEnvironment.create(env);

        //TODO 3.创建一张表 用来消费kafka数据
        tableEnv.executeSql("create table source_kafka (id String,ts bigint,vc int) with (" +
                "'connector' = 'kafka'," +
                "'topic' = 'topic_source_sensor'," +
                "'properties.bootstrap.servers' = 'hadoop102:9092'," +
                "'properties.group.id' = '0309'," +
                "'scan.startup.mode' = 'latest-offset'," +
                "'format' = 'csv'" +
                ")");

        //TODO 4.创建一张表用来往kafka写数据
        tableEnv.executeSql("create table sink_kafka (id String,ts bigint,vc int) with (" +
                "'connector' = 'kafka'," +
                "'topic' = 'topic_sink_sensor'," +
                "'properties.bootstrap.servers' = 'hadoop102:9092'," +
                "'format' = 'csv'" +
                ")");

        tableEnv.executeSql("insert into sink_kafka select * from source_kafka where id = 'sensor_1'");

    }
}
